<!DOCTYPE html>
<html lang="en">

<head>
       
    <meta charset="UTF-8">
       
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
       
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
</head>

<body>
       
    <script>
        for (var i = 1; i <= 5; i++) {
            (function (i) {
                setTimeout(function timer() {
                    console.log(i);
                }, i * 1000)
            })(i)
        }
        console.log(i);

        // var obj1={a:1,b:2,c:3,d:{e:4}}
        // var obj2={...obj1}
        // obj1.a=2;
        // obj1.d.e=5;
        // console.log(2);


        setTimeout(function () {
            console.log(1);
        }, 0)
        new Promise(function (resolve) {
            console.log(2);
            resolve();
            console.log(3);

        }).then(function () {
            console.log(4);
        })
        //输出结果: 2 3 4 1



        function newArrFn(arr) {
            for (let i = 0; i < arr.length; i++) {
                for (let j = i + 1; j < arr.length; j++) {
                    if (arr[i] === arr[j]) {
                        arr.splice(j, 1);
                        j--
                    }
                };
            }
            return arr
        }
        console.log(newArrFn(arr));


        const arr = [12, 24, 37, 24, 49, 49, 55, 68]
        const add = []
        for (let i = 0; i <= arr.length; i++) {
            if (add.indexOf(arr[i]) === -1) {
                add.push(arr[i])
            }
        }
        console.log('indexof去重', add);

        //set去重
        function setadd(arr) {
            return Array.from(new Set(arr))
        }
        console.log('set去重', setadd(arr));

    </script>
</body>

</html>